package logic

import (
	"context"
	"exam/docker/mysql"
	"exam/exzmrpc/exzmrpc"
	"exam/exzmrpc/internal/svc"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
	return &CreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateLogic) Create(in *exzmrpc.CreateRequest) (*exzmrpc.CreateResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User

	user = mysql.User{
		Title:  in.Title,
		Number: int(in.Number),
		Types:  int(in.Types),
	}

	err := mysql.DB.Debug().Create(&user).Error
	if err != nil {
		fmt.Println("添加课程失败")
	}

	return &exzmrpc.CreateResponse{
		UserId: int64(user.ID),
	}, nil
}
